package cn.itcast.test;

import cn.itcast.domain.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by lenovo on 2018/6/8.
 */
public class Dome1 {
    @Test//对象的创建
    public void test01(){

        ApplicationContext ac= new ClassPathXmlApplicationContext("applicationContext.xml");
        User user=(User)ac.getBean("User");
        User user2=(User)ac.getBean("U1");
        User user3=(User)ac.getBean("U2");
        System.out.println(user);
        System.out.println(user2);
        System.out.println(user3);
    }
    @Test//scope属性:
    public void test2(){
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        //singleton(默认)单利创建方法 在初始化容器的时候创建对象
        User user=(User)ac.getBean("User");
        User user2=(User)ac.getBean("User");
        System.out.println(user==user2);
        User user3=(User)ac.getBean("U1");
        User user4=(User)ac.getBean("U1");
        //prototype多例 会创建不同的对象
        System.out.println(user3==user4);
    }
    @Test//类似于配置构造和析构函数
    public void test3(){
        ClassPathXmlApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        User user4=(User)ac.getBean("User");
        ac.close();
        //关闭集合的方法 父接口ApplicationContext中没有,所以使用子接口
    }
}

